<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }
        
        li {
            list-style: none;
        }
        
        img {
            vertical-align: bottom;
        }
        
        #box {
            width: 1000px;
            margin: 20px auto;
            overflow: hidden;
            position: relative;
        }
        
        #back {
            width: 9999999999px;
            overflow: hidden;
        }
        
        #back li {
            float: left;
        }
        
        #previous {
            position: absolute;
            top: 45%;
            left: 10px;
        }
        
        #next {
            position: absolute;
            top: 45%;
            right: 10px;
        }
        
        #previous,
        #next {
            opacity: 0.7;
            transition: all .4s;
            cursor: pointer;
        }
        
        #previous:hover,
        #next:hover {
            opacity: 1.0;
            transform: scale(1.1);
        }
        
        #create {
            position: absolute;
            bottom: 16px;
            left: 50%;
            transform: translate(-50%, 0);
        }
        
        #create li {
            width: 14px;
            height: 14px;
            background-color: #fff;
            border-radius: 50%;
            margin-right: 5px;
            float: left;
        }
        
        #create .focus {
            background-color: indianred;
        }
    </style>
</head>

<body>
    <div id="box">
        <ul id="back" style="margin-left: 0;">
            <li>
                <img src="images/timg (2).jpg" alt="">
            </li>
            <li>
                <img src="images/2.jpg" alt="">
            </li>
            <li>
                <img src="images/timg (4).jpg" alt="">
            </li>
            <li>
                <img src="images/3.jpg" alt="">
            </li>
            <li>
                <img src="images/5.jpg" alt="">
            </li>
            <li>
                <img src="images/timg (8).jpg" alt="">
            </li>
        </ul>
        <img src="images/l.png" alt="" id="previous">
        <img src="images/r.png" alt="" id="next">

        <ul id="create">
        </ul>
</body>


<script src="jquery.min.js"></script>

<script>
    let oUl = $("#back");
    let liList = $("#back li");
    let square = $("#create");
    let n = 0; //记录当前图片的位置

    //动态创建小圆点
    liList.each(function() {

        $("<li></li>").appendTo(square);

    });
    let dotList = $("#create li");
    dotList.eq(0).addClass("focus")


    function change() {
        oUl.animate({
            marginLeft: -(n * 1000)
        });
        dotList.removeClass("focus").eq(n).addClass("focus");
    }

    //点击右箭头切换图片
    $("#next").click(function() {

        if (n !== liList.length - 1) {
            n++;
            change();
        } else {
            n = 0;
            let dotOne = liList.eq(0).clone();
            dotOne.appendTo(oUl);
            oUl.animate({
                marginLeft: -(liList.length * 1000)
            }, function() {
                dotOne.remove();
                oUl.css({
                    marginLeft: 0
                })
            });
            dotList.removeClass("focus").eq(n).addClass("focus");
        }
    })

    //点击左箭头切换图片
    $("#previous").click(function() {
        if (n !== 0) {
            n--;
            change();
        } else {
            n = liList.length - 1;
            let dotOne = liList.eq(liList.length - 1).clone();
            dotOne.prependTo(oUl);
            oUl.css({
                marginLeft: -1000
            }).animate({
                marginLeft: 0
            }, function() {
                dotOne.remove();
                oUl.css({
                    marginLeft: -1000 * (liList.length - 1)
                })
            });
            dotList.removeClass("focus").eq(n).addClass("focus");
        }
    })
</script>

</html>